package com.tddx.activiti.utils.springutils;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
 * 属性存储器
 * @author zhaoyanwei
 * spring-context 配置的properties将会被加载进来
 */
public class CustomizedPropertyConfigurer extends PropertyPlaceholderConfigurer {

	private static Map<String,String> ctxPropMap;
	
	/**
	 * 初始化时执行
	 */
	@Override
	protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)
			throws BeansException {
		super.processProperties(beanFactoryToProcess, props);
		ctxPropMap = new HashMap<String, String>();
        for (Object key : props.keySet()){
        	String keyStr = key.toString();
        	String value = String.valueOf(props.get(keyStr));
        	ctxPropMap.put(keyStr,value);
        }
	}
	
	public static String getCtxProp(String name) {
        return ctxPropMap.get(name);
    }

    public static Map<String, String> getCtxPropMap() {
        return ctxPropMap;
    }
	
}
